package com.qf.air.search.controller;

import com.qf.air.search.service.AirSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 对外提供一个功能，去ES对air索引进行增删改查
 */
@RestController
@RequestMapping("/search")
public class AirSearchController {


    @Autowired
    private AirSearchService airSearchService;

    @PostMapping("/air/list")
    public List<Map<String,Object>> list(@RequestBody Map map) throws IOException {
        // 调用service查询数据
        List<Map<String,Object>> data = airSearchService.findAirData(map);
        // 返回查询到的具体数据
        return data;
    }

    @PostMapping("/air/count")
    public Long count(@RequestBody Map map) throws IOException {
        // 调用service查询数据总条数
        Long count = airSearchService.findAirCount(map);
        // 返回查询到的数据条数
        return count;
    }

    @PostMapping("/air/add")
    public void add(@RequestBody Map map) throws IOException {
        // 调用service保存数据到ES
        airSearchService.add(map);
    }

    @PostMapping("/air/update")
    public void update(@RequestBody Map map){

        // 修改ES中的air索引数据
    }

    @PostMapping("/air/del")
    public void del(@RequestBody Map map){

        // 根据id删除air索引的数据
    }

}
